<?php
include('../PHP/autoinclude.php');
/**
 * This file is used for populating the database with information about artists
 */
/**
 * Extracts the information out of the object and stores that in the database
 * @param Artist $artist the artist to be added to the database
 */
function newArtist($artist){
   $name=$artist->name();
    $genre1=$genre2=$genre3=$genre4=$genre5='';
    $genres=$artist->genres();
    for($i=0;$i<count($genres);$i++){
        $var='genre'.($i+1);
        $$var=$genres[$i];
    }
    $years=$artist->yearActive();
    $year1=$years[0];
    $year2=$years[1];
    $listened=$artist->listened();
    $similars=$artist->similar();
    $similar1=$similar2=$similar3=$similar4=$similar5='';
    for($i=0;$i<count($similars);$i++){
        $var='similar'.($i+1);
        $$var=$similars[$i];
    }
   mysql_query("INSERT INTO MissingFull (name, listened, genre1, genre2, genre3, genre4, genre5, year1,year2,similar1,similar2,similar3,similar4,similar5) VALUES ('".$name."','".$listened."','".$genre1."','".$genre2."','".$genre3."','".$genre4."','".$genre5."','".$year1."','".$year2."','".$similar1."','".$similar2."','".$similar3."','".$similar4."','".$similar5."')");  
}
    
//
$db=new Database();
$s=new Search();
//fetch all the name from the database
$query='SELECT DISTINCT name,id FROM Missing WHERE id>87737 AND ID<98000';
$result=  mysql_query($query);
while($row=  mysql_fetch_array($result)){
   $artist=$s->getArtistFromWeb($row[0]);
   if($artist!=null){
        //if a http error occurs or there isn't enough information about the artist then $artist == null
        newArtist($artist);
        //Sometimes the script crashes, it is usefull to know where the script ended
        print($row[1]."<br>");     
   }
}

?>
